<template>
	<view>
		<view class="box">
			<!-- <image :src="loginbanner" class="sign-banner"></image> -->
			<!-- <image :src="loginlogo" class="sign-logo"></image> -->
			<view class="sign-box">
				<h3></h3>
				<h3>完善信息</h3>
				<view class="same-btn account">
					<label class="iconfont iconfonts icon-ym-people"></label>
					<input type="text" v-model="user.CompanyName" name="CompanyName" id="accountname" placeholder="输入名称">
				</view>
				<view class="same-btn account">
					<label class="iconfont iconfonts icon-ym-people"></label>
					<input type="text" v-model="user.Name" name="Name" placeholder="请输入联系人">
				</view>
				<view class="same-btn account">
					<label class="iconfont iconfonts icon-ym-people"></label>
					<input type="text" v-model="user.mobile" name="mobile" placeholder="请输入手机号">
				</view>
				<!-- <view class="same-btn password">
					<label class="iconfont iconfonts icon-ym-thecode"></label>
					<input type="password" v-model="user.Password" name="Password" id="password" placeholder="设置登录密码(不少于6个字符)">
				</view> -->
				<view class="same-btn company" >
					<label class="iconfont iconfonts icon-ym-team"></label>
					<input type="text" v-model="user.Address" placeholder="请输入地址">
				</view>
				<view class="sign-btn" @click="submit">
					保存
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '@/common/js/config.js'
	import helper from '@/common/js/helper.js'
	import graceChecker from '@/common/js/graceChecker.js'
	let rule = [{
			name: "Name",
			checkType: "notnull",
			checkRule: "",
			errorMsg: "名字不能为空"
		},
		{
			name: "mobile",
			checkType: "mobile",
			checkRule: "",
			errorMsg: "手机号不能为空"
		},
	];
	export default {
		data() {
			return {
				lookpwd: true,
				load: false,
				user: {
					Name: '孔子',
					mobile:'13096328756',
					CompanyName: '上海春申小学',
					Password: '',
					SmsCode: '',
					Address: '上海春东路790号'
				},
				loginbanner: config.Resources.banner.loginbanner,
				loginlogo: config.Resources.banner.loginlogo,
				isCompanyName: true
			}
		},
		onLoad(e) {
			this.user.SmsCode = e.smscode;
			this.user.Mobile = e.mobile;
			try {
				const value = uni.getStorageSync('AppRegisterCompanyName');
				if (value == 'hide') {
					this.isCompanyName = false;
				} else {
					this.isCompanyName = true;
				}
			} catch (e) {}
		},
		
		methods: {
			submit() {
				//console.log('返回上一页成功');
				// 在某个事件或条件下触发返回上一页操作
				uni.navigateBack({
				    delta: 1, // 返回的页面数，如果是1表示返回上一级页面，可以根据需求调整
				    success: function() {
				        console.log('返回上一页成功');
				    },
				    fail: function(error) {
				        console.error('返回上一页失败', error);
				    }
				});
			
			},
			findnext() {
				if (!graceChecker.check(this.user, rule)) {
					helper.msg(graceChecker.error);
					return
				}
				this.user.Password = helper.calcuMD5(this.user.Password);
				// let apiKey= uni.getStorageSync('apiKey') ||'NET';
				// let baseUrlObj=config.Global.baseUrl;
				// let baseUrl=config.Global.baseUrl[apiKey].apiUrl;
				uni.showLoading({ //loading提示框
					title: '正在提交，请稍等...',
					mask: true
				});
				uni.request({
					method: 'POST',
					url: config.Global.baseUrl.NET.apiUrl + '/api/Saas/Tenant/Register',
					data: this.user,
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						uni.hideLoading();
						if (res.data.code == 200) {
							uni.showToast({
								title: res.data.message,
								icon: "success",
								success: () => {
									uni.redirectTo({
										url: '/pages/users/sign-in/sign-in'
									});
								}
							});
						} else {
							helper.msg(res.data.message);
						}
					},
				});
			}
		}
	}
</script>

<style>
	.password {
		margin-bottom: 40upx;
	}

	.company {
		margin-bottom: 40upx;
	}
</style>
